/*
If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
{20,48,52}, {24,45,51}, {30,40,50}
For which value of p ≤ 1000, is the number of solutions maximised?

Anser:840
Time:39.211266ms
*/
package main

import (
	"fmt"
	"math"
	"time"
)

func main() {
	tstart := time.Now()
	maxNum, maxCount := 0, 0
	for i := 0; i <= 1000; i++ {
		n := triangles(i)
		if maxCount < n {
			maxNum, maxCount = i, n
		}
	}
	fmt.Println(maxNum)
	tend := time.Now()
	fmt.Println(tend.Sub(tstart))
}
func triangles(p int) int {
	n := 0
	for i, count := 1, int(float64(p)/(2+math.Sqrt2)); i <= count; i++ {
		for j, count := i, (p-i)/2; j < count; j++ {
			if i*i+j*j == (p-i-j)*(p-i-j) {
				n++
			}
		}
	}
	return n
}
